package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.framework.utils.CollectionUtils;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.GroupResourceMapper;
import com.molichuxing.services.infrastructure.dto.response.response.GroupResourceDto;
import com.molichuxing.services.infrastructure.service.GroupResourceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("groupResourceService")
public class GroupResourceServiceImpl implements GroupResourceService {
    private static final Logger logger = LoggerFactory.getLogger(GroupResourceServiceImpl.class);

    @Resource
    private GroupResourceMapper groupResourceMapper;

    @Override
    public List<GroupResourceDto> getGroupResourceListByParm(Map<String, Object> param) {
        return Convert.toGroupResourceDtoList(groupResourceMapper.getGroupResourceListByParam(param));
    }

    /**
     * 批量添加
     * @param groupId
     * @param resourceIds
     * @return
     */
    @Override
    public int createBatchGroupResource(int groupId, List<Integer> resourceIds) {
        if (groupId <= 0 ) {
            throw new IllegalArgumentException("param invalid groupId is :" +groupId+ "  resourceIds is : " +resourceIds);
        }
        return groupResourceMapper.createBatchGroupResource(groupId, resourceIds);
    }

    /**
     * 根据groupId删除
     * @param groupId
     * @return
     */
    @Override
    public int deleteByGroupId(int groupId) {
        return groupResourceMapper.deleteByGroupId(groupId);
    }

    @Override
    public int deleteByResourceId(int resourceId) {
        return groupResourceMapper.deleteByResourceId(resourceId);
    }
}
